<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>bfc</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box1 {
        width: 100px;
        height: 100px;
        background-color: green;
        margin-top: 50px;
        overflow: hidden; /* 开启 BFC，解决 margin 重叠问题 */
      }
      .box2 {
        width: 50px;
        height: 50px;
        margin-top: 50px;
        background-color: yellowgreen;
      }

      .box3 {
        width: 100px;
        background-color: green;
        overflow: hidden; /* 开启 BFC，清除浮动，防止高度塌陷 */
      }
      .box4 {
        width: 50px;
        height: 50px;
        background-color: yellowgreen;
        float: left;
      }

      .box5 {
        height: 200px;
        background-color: green;
      }
      .box6 {
        width: 100px;
        height: 100px;
        background-color: yellowgreen;
        float: left;
      }
      .box7 {
        width: 100px;
        height: 100px;
        background-color: yellow;
        /* float: left; */ /* 开启BFC 阻止标准流元素被浮动元素覆盖 */
        overflow: hidden;
      }
    </style>
  </head>
  <body>
    <!-- 
    ● 阻止 margin 重叠
    ● 清除浮动，防止高度塌陷
    ● 阻止标准流元素被浮动元素覆盖
   -->
    <div class="box1">
      <div class="box2"></div>
    </div>

    <hr style="margin: 20px 0" />

    <div class="box3">
      <div class="box4"></div>
    </div>

    <hr style="margin: 20px 0" />

    <div class="box5">
      <div class="box6">box6</div>
      <div class="box7">box7</div>
    </div>
  </body>
</html>
